package leetcode.leetcode_560;

class Solution {
    public int subarraySum(int[] nums, int k) {
        int n = nums.length;
        int count = 0 ;
        int[] sumArr = new int[n];
        sumArr[0] = nums[0];
        for (int i = 1; i < n; i++) {
            sumArr[i] = sumArr[i - 1] + nums[i];
        }
        for (int i = 0; i < n; i++){
            if (sumArr[i] == k) count++;
            for (int j = 0; j < i; j++) {
                if (sumArr[i] - sumArr[j] == k) count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,3};
        int k = 3;
        System.out.println(new Solution().subarraySum(nums, k));
    }
}